function inClient(table,i,name,prin,tell,zone,unit,dept,able){
    name = name?name:"";
    prin = prin?prin:"";
    tell = tell?tell:"";
    zone = zone?zone:"";
    unit = unit?unit:"";
    dept = dept?dept:"";
    able = able?true:false;
    
    //tbody.parentElement.childNodes[1].removeNode(true);
    
    var lastTbody = table.lastChild;
    
    var tbody = document.createElement("<tbody id='tClient" + number + "'>");
     
    //line 1
    var tr = document.createElement("<tr>");
    var td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right' colspan='1'>");
    td.innerText = "客户名称：";
    tr.appendChild(td);
    
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right' colspan='3'>");
    td.innerHTML = "<input name='cname_" + number + "' value='"+ name +"' type='text' size = '76' style = 'width: 100%'/>";
    tr.appendChild(td);
    tbody.appendChild(tr);
    
   
     //line 2
    tr = document.createElement("<tr>");
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerText = "负责人：";
    tr.appendChild(td);

    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerHTML = "<input name='cprincipal_" + number  + "' value='"+ prin +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerText = "联系电话：";
    tr.appendChild(td);
    
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerHTML = "<input name='ctelephone_" + number  + "' value='"+ tell +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    tbody.appendChild(tr);
    
    //line 3
    tr = document.createElement("<tr>");
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerText = "所属地域：";
    tr.appendChild(td);

    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerHTML = "<input name='czone_" + number  + "' value='"+ zone +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerText = "所属单位：";
    tr.appendChild(td);
    
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerHTML = "<input name='cunit_" + number  + "' value='"+ unit +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    tbody.appendChild(tr);
    
    //line 4
    tr = document.createElement("<tr>");
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerText = "所属部门：";
    tr.appendChild(td);
    
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerHTML = "<input name='cdept_" + number  + "' value='"+ dept +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    
    if(!able){
	    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right' colspan='2'>");
	    if(i != 0){
	        td.innerHTML = "<input type='button' value='删除' onmouseover='this.className=\"input_btn2\"' onmouseout='this.className=\"input_btn1\"' class='input_btn1' onclick='javascript:deClient(tClient" + number + ")'/>"
	    }else{
	        td.innerHTML = "<input type='button' value='添加' onmouseover='this.className=\"input_btn2\"' onmouseout='this.className=\"input_btn1\"' class='input_btn1' onclick='javascript:inClient(clients)'/>"
	    }
	    tr.appendChild(td);
    
    }
    
    tbody.appendChild(tr);
    //alert(table.appendChild);
    table.appendChild(tbody);
    
    //alert('111');
    tr = document.createElement("<tr id='line'>");
    td = document.createElement("<td height='5%' align='right' colspan='4'>");
    td.innerHTML = "<hr size='1'/>";
    tr.appendChild(td);
    if(i != 0){
       lastTbody.appendChild(tr);
    }
    number ++;
    //alert(tbody.innerHTML);
}


function initClient(table,clients,able){
    //alert(clients.length);
    for(var i=0; i<clients.length; i++){
       inClient(table,i,clients[i].name,clients[i].principal,clients[i].telephone,clients[i].zone,clients[i].unit,clients[i].dept,able);
    }   
}

function inDpt(table,i,dept,prin,able){
    //tbody.parentElement.childNodes[1].removeNode(true);
    //alert(table.appendChild);
    dept = dept?dept:"";
    prin = prin?prin:"";
    
    var lastTbody = table.lastChild;
    
    var tbody = document.createElement("<tbody id='tDpt" + number + "'>");


     //line 1
    var tr = document.createElement("<tr>");
    var td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerText = "技术负责部门：";
    tr.appendChild(td);

    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerHTML = "<input name='tdept_" + number + "' value='" + dept +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerText = "技术负责人：";
    tr.appendChild(td);
    
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right'>");
    td.innerHTML = "<input name='tprincipal_" + number + "' value='" + prin +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    //tbody.appendChild(tr);
    
    
    
    //line 4
    //tr = document.createElement("<tr>");
  if(!able){
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right' colspan='1'>");
    if(i != 0){
        td.innerHTML = "<input type='button' value='删除' onmouseover='this.className=\"input_btn2\"' onmouseout='this.className=\"input_btn1\"' class='input_btn1' onclick='javascript:deClient(tDpt" + number + ")'/>"
    }else{
	    td.innerHTML = "<input type='button' value='添加' onmouseover='this.className=\"input_btn2\"' onmouseout='this.className=\"input_btn1\"' class='input_btn1' onclick='javascript:inDpt(dpts)'/>"
    }tr.appendChild(td);
    }
    tbody.appendChild(tr);
    
    
    table.appendChild(tbody);
    
    
    tr = document.createElement("<tr id='line'>");
    td = document.createElement("<td height='5%' align='right' colspan='5'>");
    td.innerHTML = "<hr size='1'/>";
    tr.appendChild(td);
    if(i != 0){
      lastTbody.appendChild(tr);
    }
    number ++;
    //alert(tbody.innerHTML);
}

function initDpt(table,depts,able){
   //alert(depts[0].dept);
   for(var j=0; j<depts.length; j++){
       inDpt(table,j,depts[j].dept,depts[j].principal,able);
   }
}

function initLeader(table,leaders,able){
   //alert(depts[0].dept);
   for(var j=0; j<leaders.length; j++){
       inLeader(table,j,leaders[j].name,leaders[j].dept,leaders[j].phone,leaders[j].email,able);
   }
}
function initStaticLeader(table,leaders,able){
   for(var j=0; j<leaders.length; j++){
       inStaticLeader(table,j,leaders[j].name,leaders[j].dept,leaders[j].phone,leaders[j].email);
   }
}

function inLeader(table,i,name,dept,phone,email,able){
    //tbody.parentElement.childNodes[1].removeNode(true);
    //alert(table.appendChild);
    name = name?name:"";
    dept = dept?dept:"";
    phone = phone?phone:"";
    email = email?email:"";
         
    var lastTbody = table.lastChild;
    
    var tbody = document.createElement("<tbody id='Leader" + number + "'>");


     //line 1
    var tr = document.createElement("<tr>");
    var td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "姓名：";
    tr.appendChild(td);

    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerHTML = "<input name='name_" + number + "' value='" + name +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "部门：";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerHTML = "<input name='dept_" + number + "' value='" + dept +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    tbody.appendChild(tr);
    
    tr = document.createElement("<tr>");
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "电话：";
    tr.appendChild(td);

    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerHTML = "<input name='phone_" + number + "' value='" + phone +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "email：";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerHTML = "<input name='email_" + number + "' value='" + email +"' type='text' style='width: 100%'/>";
    tr.appendChild(td);
    tbody.appendChild(tr);
    
    
    //line 4
    //tr = document.createElement("<tr>");
  if(!able){
    tr = document.createElement("<tr>");
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right' colspan='4'>");
    if(i != 0){
        td.innerHTML = "<input type='button' value='删除' onmouseover='this.className=\"input_btn2\"' onmouseout='this.className=\"input_btn1\"' class='input_btn1' onclick='javascript:deLeader(Leader" + number + ")'/>"
    }else{
	    td.innerHTML = "<input type='button' value='添加' onmouseover='this.className=\"input_btn2\"' onmouseout='this.className=\"input_btn1\"' class='input_btn1' onclick='javascript:inLeader(Leader)'/>"
    }
    tr.appendChild(td);
    tbody.appendChild(tr);
   }
    table.appendChild(tbody);
    
    
    tr = document.createElement("<tr id='line'>");
    td = document.createElement("<td height='5%' align='right' colspan='5'>");
    td.innerHTML = "<hr size='1'/>";
    tr.appendChild(td);
    if(i != 0){
      lastTbody.appendChild(tr);
    }
    number ++;
    //alert(tbody.innerHTML);
}
function inStaticLeader(table,i,name,dept,phone,email){
    //tbody.parentElement.childNodes[1].removeNode(true);
    //alert(table.appendChild);
    name = name?name:"";
    dept = dept?dept:"";
    phone = phone?phone:"";
    email = email?email:"";
         
    var lastTbody = table.lastChild;
    
    var tbody = document.createElement("<tbody id='Leader" + number + "'>");


     //line 1
    var tr = document.createElement("<tr>");
    var td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "姓名：";
    tr.appendChild(td);

    td = document.createElement("<td class='tdCss' align='left'>");
    td.innerHTML = name;
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "部门：";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='left'>");
    td.innerHTML = dept;
    tr.appendChild(td);
    tbody.appendChild(tr);
    
    tr = document.createElement("<tr>");
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "电话：";
    tr.appendChild(td);

    td = document.createElement("<td class='tdCss' align='left'>");
    td.innerHTML = phone;
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "email：";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='left'>");
    td.innerHTML = email;
    tr.appendChild(td);
    tbody.appendChild(tr);
    
    
    //line 4
    //tr = document.createElement("<tr>");
  
    table.appendChild(tbody);
    
    
    tr = document.createElement("<tr id='line'>");
    td = document.createElement("<td height='5%' align='right' colspan='5'>");
    td.innerHTML = "<hr size='1'/>";
    tr.appendChild(td);
    if(i != 0){
      lastTbody.appendChild(tr);
    }
    number ++;
    //alert(tbody.innerHTML);
}

function deClient(tbody){
 var table = tbody.parentElement;
 tbody.removeNode(true);
 if(table.lastChild.lastChild.id == 'line'){
    table.lastChild.lastChild.removeNode(true);
 }
}
function deLeader(tbody){
 var table = tbody.parentElement;
 tbody.removeNode(true);
 if(table.lastChild.lastChild.id == 'line'){
    table.lastChild.lastChild.removeNode(true);
 }
}
function deDpt(tbody){
 var table = tbody.parentElement;
 tbody.removeNode(true);
 if(table.lastChild.lastChild.id == 'line'){
    table.lastChild.lastChild.removeNode(true);
 }
}

function inTellAttach(table,name){
    //tbody.parentElement.childNodes[1].removeNode(true);
    
    var lastTbody = table.lastChild;
    
    var tbody = document.createElement("<tbody id='" + name + number + "'>");


     //line 1
    var tr = document.createElement("<tr>");
    var td = document.createElement("<td bgcolor='#F4FAFE' width='75%' align='right' colspan='3'>");
    td.innerHTML = "<input name='"+ name+ "' type='file' style='width: 100%'/>";
    tr.appendChild(td);
         
    td = document.createElement("<td bgcolor='#F4FAFE' width='25%' align='right' colspan='1'>");
    td.innerHTML = "<input type='button' value='删除' onmouseover='this.className=\"input_btn2\"' onmouseout='this.className=\"input_btn1\"' class='input_btn1' onclick='javascript:deClient("+ name + number + ")'/>"
    tr.appendChild(td);
    
    tbody.appendChild(tr);
    
    
    table.appendChild(tbody);
    number ++;
    //alert(tbody.innerHTML);
}
function deTellAttach(tbody){
 var table = tbody.parentElement;
 tbody.removeNode(true);
 if(table.lastChild.lastChild.id == 'line'){
    table.lastChild.lastChild.removeNode(true);
 }
}


//静态展现


function initSaticDpt(table,depts){
   //alert(depts[0].dept);
   for(var j=0; j<depts.length; j++){
       inSaticDpt(table,j,depts[j].dept,depts[j].principal);
   }
}
function inSaticDpt(table,i,dept,prin){

    var lastTbody = table.lastChild;
    
    var tbody = document.createElement("<tbody id='tDpt" + number + "'>");


     //line 1
    var tr = document.createElement("<tr>");
    var td = document.createElement("<td class='tdCss'  align='right'>");
    td.innerText = "技术负责部门：";
    tr.appendChild(td);

    td = document.createElement("<td class='tdCss' align='left'>");
    td.innerHTML = dept;
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "技术负责人：";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='left'>");
    td.innerHTML = prin;
    tr.appendChild(td);
    //tbody.appendChild(tr);
    

    tbody.appendChild(tr);
    
    
    table.appendChild(tbody);
    
    
    tr = document.createElement("<tr id='line'>");
    td = document.createElement("<td height='5%' align='right' colspan='5'>");
    td.innerHTML = "<hr size='1'/>";
    tr.appendChild(td);
    if(i != 0){
      lastTbody.appendChild(tr);
    }
    number ++;
    //alert(tbody.innerHTML);
}


function inSaticClient(table,i,name,prin,tell,zone,unit,dept){

    var lastTbody = table.lastChild;
    
    var tbody = document.createElement("<tbody id='tClient" + number + "'>");
     
    //line 1
    var tr = document.createElement("<tr>");
    var td = document.createElement("<td class='tdCss' align='right' colspan='1'>");
    td.innerText = "客户名称：";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='left' colspan='3'>");
    td.innerHTML = name;
    tr.appendChild(td);
    tbody.appendChild(tr);
    
   
     //line 2
    tr = document.createElement("<tr>");
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "负责人：";
    tr.appendChild(td);

    td = document.createElement("<td class='tdCss' align='left'>");
    td.innerHTML = prin;
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "联系电话：";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='left'>");
    td.innerHTML = tell;
    tr.appendChild(td);
    tbody.appendChild(tr);
    
    //line 3
    tr = document.createElement("<tr>");
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "所属地域：";
    tr.appendChild(td);

    td = document.createElement("<td class='tdCss' align='left'>");
    td.innerHTML = zone;
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "所属单位：";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='left'>");
    td.innerHTML = unit;
    tr.appendChild(td);
    tbody.appendChild(tr);
    
    //line 4
    tr = document.createElement("<tr>");
    td = document.createElement("<td class='tdCss' align='right'>");
    td.innerText = "所属部门：";
    tr.appendChild(td);
    
    td = document.createElement("<td class='tdCss' align='left'  colspan='3'>");
    td.innerHTML = dept;
    tr.appendChild(td);
    
    tbody.appendChild(tr);
    //alert(table.appendChild);
    table.appendChild(tbody);
    
    //alert('111');
    tr = document.createElement("<tr id='line'>");
    td = document.createElement("<td height='5%' align='right' colspan='4'>");
    td.innerHTML = "<hr size='1'/>";
    tr.appendChild(td);
    if(i != 0){
       lastTbody.appendChild(tr);
    }
    number ++;
    //alert(tbody.innerHTML);
}


function initSaticClient(table,clients){
    //alert(clients.length);
    for(var i=0; i<clients.length; i++){
       inSaticClient(table,i,clients[i].name,clients[i].principal,clients[i].telephone,clients[i].zone,clients[i].unit,clients[i].dept);
    }   
}
